using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleJson;
using System;
using FairyGUI;

namespace ABA
{
    public class SysLoadingNet : Singleton<SysLoadingNet>
    {
        private class LoadingNetWin : FGUIWindow
        {
            public LoadingNetWin(FGUIWinInfo type):base(type){
            }

            protected override void OnInit()
            {
                base.OnInit();
                Center();
                //阻挡点击事件
                SetBlockEvent(true, null, E_DLG_MASK_TYPE.EMPTY);     
            }
            // float curTime = 0;

            long _showLoadingTimerId = 0;
            public void ShowLoading(){
                contentPane.asCom.GetChild("loading_ani").visible = false;
                // contentPane.fairyBatching = false;
                // contentPane.InvalidateBatchingState();
                GameTimer.inst.Remove(_showLoadingTimerId);
                _showLoadingTimerId = GameTimer.inst.Add(0.5f,1,ShowLoadingAni);  

                Show();
            }
            public void HideLoading(){
                GameTimer.inst.Remove(_showLoadingTimerId);   
                Hide();
            }
            
            private void ShowLoadingAni(JsonObject p)
            {
                contentPane.asCom.GetChild("loading_ani").visible = true;
                contentPane.asCom.GetChild("loading_ani").asMovieClip.playing = true;
            }
        }

        LoadingNetWin wind;
        protected override void Init(){
            var SYS_LOADINGNET = new FGUIWinInfo
            {
                cls_name = "LoadingNetWin",
                pkg_name = "sys",
                comp_name = "loading_net",
                zindex = E_FGUIWIN_ZINDEX.LOADING,
                ani = false
            };

            // wind = new LoadingNetWin(WinConst.SYS_LOADINGNET);         
            wind = new LoadingNetWin(SYS_LOADINGNET);  
            wind.Show();  // 为了调用 OnInit()
            wind.Hide();       
        }

        // 外部主动调用 Hide关闭
        public void ShowLoading(){
            wind.ShowLoading();
        }

        public void Hide(bool force = false){
            wind.HideLoading();
        }
    }
}
